package eom.example.elasticsearch.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import eom.example.elasticsearch.domain.CmsContent;
import eom.example.elasticsearch.service.CmsContentService;
import eom.example.elasticsearch.mapper.CmsContentMapper;
import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Service;

/**
 *
 */
@Service
public class CmsContentServiceImpl extends ServiceImpl<CmsContentMapper, CmsContent>
    implements CmsContentService{


    @Override
    public IPage<CmsContent> pageCmsContent(Integer page, Integer size, String keyword) {
        LambdaQueryWrapper<CmsContent> lambdaQueryWrapper=new LambdaQueryWrapper();
        if(StringUtils.isNotBlank(keyword)){
            lambdaQueryWrapper.or().like(CmsContent::getAuthor,keyword);
            lambdaQueryWrapper.or().like(CmsContent::getSubTitle,keyword);
            lambdaQueryWrapper.or().like(CmsContent::getTitleName,keyword);
            lambdaQueryWrapper.or().like(CmsContent::getTags,keyword);
        }
        lambdaQueryWrapper.orderByDesc(CmsContent::getCreateDate);
        Page page1=new Page(page,size);
        IPage<CmsContent> contentIPage=this.baseMapper.selectPage(page1,lambdaQueryWrapper);
        return contentIPage;
    }
}




